//
// This file is part of cpp-lib, a library of C++ functions and classes.
// Cpp-lib is copyright (C) 2004 and onwards, The CPL Interest Group.
// 
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or (at
// your option) any later version.
// 
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
// General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this library (see the file COPYING); if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
// 02111-1307  USA
//
// $Id$
//

#include <iostream>
#include <iterator>
#include <string>
#include <exception>
#include <stdexcept>
#include <algorithm>
#include <memory>

#include <cassert>


#include "cpp-lib/network.h"
#include "cpp-lib/util.h"

using namespace cpl::util::network ;

std::string const port = "4711" ;


void usage( std::string const& name ) {

  std::cerr << 
    "usage: " << name << " local port\n"
    "usage: " << name << " remote host remote port\n"
  ;

}


int main( int argc , char const* const* const argv ) {

  try {

  if( 2 == argc ) {

    stream_address a( argv[ 1 ] ) ;

    for( unsigned i = 0 ; i < a.size() ; ++i ) {

      std::cout << name( a.at( i ) ) << '\n' ;

    }

  } else if( 3 == argc ) {
    
    node_service const ns( argv[ 1 ] , argv[ 2 ] ) ;
    stream_address const a( ns ) ;

    for( unsigned i = 0 ; i < a.size() ; ++i ) {

      std::cout << name( a.at( i ) ) << '\n' ;

    }

  } else {

    usage( argv[ 0 ] ) ;
    return 1 ;

  }

  } // end global try

  catch( std::exception const& e ) 
  { cpl::util::die( e.what() ) ; }

}
